import { UPDATEUSERINFO, CLEARUSERINFO } from '../types/userinfo'
import { handleActions } from 'redux-actions'
import { getStorageSync, setStorageSync } from '../../crossplatform/apiservice/storage'

const Schema = {
  userId: '', // 252600
  openId: '',
  zhichuUserId: '', // 37 //34
  zhichuUserIdB: '', // 1
  role: 'personal', // company || personal
  companyId: '',
  userInfoC: {
    userAvator: '',
    mobile: '',
    userName: ''
  },
  userInfoB: {
    userAvator: '',
    mobile: '',
    userName: ''
  },
  isVip: false,
  vipEndTime: '',
  archiveComplete: 0,
  latitude: '',
  longitude: '',
  mobile: ''
}

export default handleActions(
  {
    [UPDATEUSERINFO] (state, action) {
      let userinfo = {
        ...state,
        ...action.payload
      }
      setStorageSync('userinfo', { ...userinfo })
      return {
        ...userinfo
      }
    },
    [CLEARUSERINFO](state, action) {
      let newState = Schema
      setStorageSync('userinfo', Schema)

      return {
        ...newState
      }
    }
  },
  Schema
)
